package com.imooc.imoocbilibili.controller;

import com.imooc.imoocbilibili.entity.Video;
import com.imooc.imoocbilibili.entity.VideoCoin;
import com.imooc.imoocbilibili.entity.VideoCollection;
import com.imooc.imoocbilibili.service.VideoService;
import com.imooc.imoocbilibili.utils.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * 视频投稿记录表
 *
 * @author jl
 * @since 2022-04-10 21:13:43
 */
@RestController
@RequiredArgsConstructor
public class VideoController {

    private final VideoService videoService;

    /**
     * 视频投稿
     */
    @PostMapping("/videos")
    public R addVideos(@RequestBody Video video) {
        videoService.addVideos(video);
        return R.ok();
    }

    /**
     * 分页查询视频投稿记录表
     */
    @GetMapping("/videos")
    public R list(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestParam("area") String area) {
        return R.ok(videoService.queryPage(pageNo, pageSize, area));
    }


    /**
     * 视频在线播放
     */
    @GetMapping("/video-slices")
    public void viewVideoOnlineBySlices(HttpServletRequest request,
                                        HttpServletResponse response,
                                        String path) throws Exception{
        videoService.viewVideoOnlineBySlices(request, response, path);
    }

    /**
     * 点赞视频
     */
    @PostMapping("/video-likes")
    public R addVideoLike(@RequestParam Long videoId) {
        videoService.addVideoLike(videoId);
        return R.ok();
    }

    /**
     * 取消视频点赞
     */
    @DeleteMapping("/video-likes")
    public R deleteVideoLike(@RequestParam Long videoId) {
        videoService.deleteVideoLike(videoId);
        return R.ok();
    }

    /**
     * 查询视频点赞数量
     */
    @GetMapping("/video-likes")
    public R getVideoLike(@RequestParam Long videoId) {
        return R.ok(videoService.getVideoLike(videoId));
    }

    /**
     * 收藏视频
     */
    @PostMapping("/video-collections")
    public R addVideoCollection(@RequestBody VideoCollection videoCollection){
        videoService.addVideoCollection(videoCollection);
        return R.ok();
    }

    /**
     * 取消收藏视频
     */
    @DeleteMapping("/video-collections")
    public R deleteVideoCollection(@RequestParam Long videoId){
        videoService.deleteVideoCollection(videoId);
        return R.ok();
    }

    /**
     * 查询视频收藏数量
     */
    @GetMapping("/video-collections")
    public R getVideoCollections(@RequestParam Long videoId){
        return R.ok(videoService.getVideoCollections(videoId));
    }

    /**
     * 视频投币
     */
    @PostMapping("/video-coins")
    public R addVideoCoins(@RequestBody VideoCoin videoCoin){
        videoService.addVideoCoins(videoCoin);
        return R.ok();
    }

    /**
     * 查询视频投币数量
     */
    @GetMapping("/video-coins")
    public R getVideoCoins(@RequestParam Long videoId){
        return R.ok(videoService.getVideoCoins(videoId));
    }

    /**
     * 获取视频详情
     */
    @GetMapping("/video-details")
    public R getVideoDetails(@RequestParam Long videoId){
        Map<String, Object> result = videoService.getVideoDetails(videoId);
        return R.ok();
    }

}
